package com.fishingwithme.infrastructure.dtos.circle;

import com.fishingwithme.domain.spots.FishType;
import com.fishingwithme.domain.spots.ParkingDistance;
import com.fishingwithme.domain.spots.SpotType;
import com.fishingwithme.domain.spots.WaterType;
import com.fishingwithme.infrastructure.dtos.anybiting.MessageContentBody;
import com.fishingwithme.infrastructure.utils.CommonUtils;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Data;
import org.json.JSONException;

import java.util.List;

@Data
public class CircleNewSpotEventDto implements MessageContentBody {
    private Long id;
    private String city;
    private String name;
    private Boolean isFree;

    private ObjectNode wType;
    private String waterType;

    private String spotTypes;
    private List<ObjectNode> sTypes;

    private String fishTypes;
    private List<ObjectNode> fTypes;

    private String distance;
    private ObjectNode dType;

    private Boolean isPrivate;

    private String pictures;
    private List<String> pics;

    public static CircleNewSpotEventDto format(CircleNewSpotEventDto dto) throws JSONException {
        dto.setSTypes(CommonUtils.convert(dto.getSpotTypes(), SpotType.class));
        dto.setSpotTypes(null);
        dto.setFTypes(CommonUtils.convert(dto.getFishTypes(), FishType.class));
        dto.setFishTypes(null);
        dto.setPics(CommonUtils.convert(dto.getPictures(), String.class));
        dto.setPictures(null);
        if (dto.getDistance() != null) {
            dto.setDType(ParkingDistance.valueOf(dto.getDistance()).toJson());
            dto.setDistance(null);
        }
        if (dto.getWaterType() != null) {
            dto.setWType(WaterType.valueOf(dto.getWaterType()).toJson());
            dto.setWaterType(null);
        }
        return dto;
    }


    @Override
    public void format() {
        try {
            format(this);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }
}
